package main;

import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

import tools.MainChannel;
import tools.Message;

public class ClientMain {

	private Selector selector;
	private String ip;
	private int port;
	
	public ClientMain(String ip, int port){
		this.ip = ip;
		this.port = port;
	}
	
	public void startClient(){
		try{
			selector = Selector.open();
			
			SocketChannel sc = SocketChannel.open(new InetSocketAddress(ip,port));
			sc.configureBlocking(false);
			sc.register(selector, SelectionKey.OP_READ);
			
			MainChannel.setChannel(sc);
			
			ReceiveControl r = new ReceiveControl(selector);
			r.start();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
